package demo;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

import javax.net.SocketFactory;
import javax.net.ssl.SSLSocketFactory;

public class SSLclient {

	public static void sslConnect() throws Exception {

		int port = 4430;
		String hostname = "localhost";
		SocketFactory socketFactory = SSLSocketFactory.getDefault();
		Socket socket = socketFactory.createSocket(hostname, port);

		// Create streams to securely send and receive data to the server
		InputStream in = socket.getInputStream();
		OutputStream out = socket.getOutputStream();
		String req = "GET / HTTP/1.0\r\n\r\n";
		out.write(req.getBytes());
		out.flush();
		BufferedReader r = new BufferedReader( new InputStreamReader(in) );
		String line;
		
		while( (line=r.readLine())!=null){
			System.out.println(line);
		}
		
		in.close();
		out.close();

	}

	public static void main(String[] args) throws Exception {
		sslConnect();

	}
}
